package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.SystemSvg;
import com.econ.powercloud.ems.dal.mapper.SystemSvgMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author jwc
 * @date 2023/05/08
 */
@Repository
public class SystemSvgDAO extends ServiceImpl<SystemSvgMapper, SystemSvg> {

    public List<SystemSvg> selectByParentId(Integer parentId) {
        LambdaQueryWrapper<SystemSvg> wrapper = Wrappers.<SystemSvg>lambdaQuery()
                .eq(SystemSvg::getParentId, parentId);
        return this.getBaseMapper().selectList(wrapper);
    }

    public List<SystemSvg> selectListByCondition(String relationId,String relationType,Integer type,String tag) {
        LambdaQueryWrapper<SystemSvg> wrapper = Wrappers.<SystemSvg>lambdaQuery();
        wrapper.eq(StringUtils.isNotBlank(relationId),SystemSvg::getRelationId, relationId);
        wrapper.eq(StringUtils.isNotBlank(relationType),SystemSvg::getRelationType,relationType);
        wrapper.eq(type != null,SystemSvg::getType,type);
        wrapper.eq(StringUtils.isNotBlank(tag),SystemSvg::getTag,tag);
        return this.getBaseMapper().selectList(wrapper);
    }

    public Integer deleteByRelationIdAndRelationType(String relationId,String relationType) {
        LambdaQueryWrapper<SystemSvg> wrapper = Wrappers.<SystemSvg>lambdaQuery()
                .eq(SystemSvg::getRelationId, relationId)
                .eq(SystemSvg::getRelationType,relationType);
        return this.getBaseMapper().delete(wrapper);
    }
}
